package com.cloud.example.business.flow.controller.depend.dependnew.worker;


import com.cloud.async.flow.callback.ICallback;
import com.cloud.async.flow.callback.IWorker;
import com.cloud.async.flow.worker.WorkResult;
import com.cloud.async.flow.wrapper.WorkerWrapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.Map;


public class DeWorker1 implements IWorker<String, User>, ICallback<String, User> {
    /**
     * logger
     */
    private final Log logger = LogFactory.getLog(getClass());


    @Override
    public User action(String object, Map<String, WorkerWrapper> allWrappers) {
        WorkResult first = allWrappers.get("first").getWorkResult();
        logger.info("worker1 入参:" + first.getResult());
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        User user0 = (User) allWrappers.get("first").getWorkResult().getResult();
        return new User(user0.getName() + " worker1 add");
    }

    @Override
    public User defaultValue() {
        return new User("default User");
    }

    @Override
    public void begin() {

    }

    @Override
    public void result(boolean success, String param, WorkResult<User> workResult) {
        logger.info("worker1 的结果是：" + workResult.getResult());
    }

}
